//
// Created by root on 11/7/18.
//

#ifndef URSAX_ENDPOINTS_H
#define URSAX_ENDPOINTS_H

#include <stdint.h>
#include <string.h>

#include "anysocket.h"
#include "log.h"

#ifdef __cplusplus
extern "C" {
#endif

struct EndPoints;
typedef struct EndPoints EndPoints_t;

extern EndPoints_t all_managers;
extern EndPoints_t all_redis_servers;

extern uint32_t manager_ip;
extern uint16_t manager_port;
extern uint16_t redis_port;
extern char redis_ip[32];

void parse_endpoints(const char *str_eps, EndPoints_t * eps, uint16_t default_port);
st_netfd_t get_a_connection(EndPoints_t *eps, uint32_t *ip, uint16_t *port);
int get_an_endpoint(EndPoints_t * eps, uint32_t *ip, uint16_t *port);
void add_a_endpoint(EndPoints_t *eps, uint32_t ip, uint16_t port);
int get_endpoints_nb(EndPoints_t *eps);
void parse_redis_servers(const char *str_ep);
void parse_managers(const char *str_ep);
void remove_endpoint_from_redis_servers(int index);

int get_a_redis_server_str(char *ip, uint16_t *port);
int get_redis_servers_nb(void);
bool do_redis_servers_contain_port(uint16_t port, int *index);
st_netfd_t get_a_manager_connection(void);

void add_a_manager(uint32_t ip, uint16_t port);

#ifdef __cplusplus
}
#endif

#endif //URSAX_ENDPOINTS_H
